#include"iostream"

using namespace std;

const int N = 100010;

int stack[N], n, m;

void push(int x)
{
	stack[n++] = x;
}

int pop()
{
	return stack[n--];
}

int query()
{
	return stack[n];
}

string empty()
{
	return !n ? "YES" : "NO";
}


int main()
{
	scanf("%d",&m);
	string op;
	while(m--){
		int x;
		cin >> op;
		if(op == "push") cin >> x, push(x);
		else if(op == "query") cout << query() << endl;
		else if(op == "pop") pop();
		else cout << empty() << endl;
	}
}